#include "StdAfx.h"
#include "Color4.h"


CColor4::CColor4(void)
: r(0.f), g(0.f), b(0.f), a(1.f)
{
}

CColor4::CColor4(DATA_TYPE r, DATA_TYPE g, DATA_TYPE b, DATA_TYPE a)
{
	this->r = r;
	this->g = g;
	this->b = b;
	this->a = a;
}

CColor4::~CColor4(void)
{
}

CColor4 CColor4::operator+(const CColor4& rhs) const
{
	return CColor4(this->r + rhs.r, this->g + rhs.g, this->b + rhs.b, this->a + rhs.a);
}

CColor4 CColor4::operator*(const CColor4& rhs) const
{
	return CColor4(this->r * rhs.r, this->g * rhs.g, this->b * rhs.b, this->a * rhs.a);
}

CColor4 CColor4::operator*(float fScalar) const
{
	CColor4 ret;
	ret.r = fScalar * this->r;
	ret.g = fScalar * this->g;
	ret.b = fScalar * this->b;
	ret.a = fScalar * this->a;
	return ret;
}

CColor4 CColor4::operator/(float fScalar) const
{
	CColor4 ret;
	ret.r = this->r / fScalar;
	ret.g = this->g / fScalar;
	ret.b = this->b / fScalar;
	ret.a = this->a / fScalar;
	return ret;
}

CColor4 operator*(DATA_TYPE fScalar, const CColor4& col)
{
	return col * fScalar;
}

CColor4& CColor4::operator+=(const CColor4& rhs)
{
	this->r += rhs.r;
	this->g += rhs.g;
	this->b += rhs.b;
	this->a += rhs.a;
	return *this;
}

CColor4& CColor4::operator/=(DATA_TYPE fScalar)
{
	this->r /= fScalar;
	this->g /= fScalar;
	this->b /= fScalar;
	this->a /= fScalar;
	return *this;
}

DATA_TYPE CColor4::GetSquaredColorDistance(const CColor4& rhs) const
{
	DATA_TYPE fDistance = 0.f;
	fDistance += (this->r - rhs.r) * (this->r - rhs.r)
			   + (this->g - rhs.g) * (this->g - rhs.g)
			   + (this->b - rhs.b) * (this->b - rhs.b);
	return fDistance;
}